package com.zjtaixue.usersite.page;

import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;


/**
 * 分页对象
 * Created by Administrator on 2017/7/12.
 */
@Data
public class PageResult<T> implements Serializable{

    //数据集合
    private List<T> listData;

    private Integer pageSize;//每页数据大小
    private Integer currentPage;//当前页
    private Integer nextPage;//下一页
    private Integer prevPage;//上一页
    private Integer totalPage;//总页数
    private Integer totalCount;//总记录数

    public static PageResult empty(Integer pageSize) {
        return new PageResult(Collections.EMPTY_LIST, 0, 1, pageSize);
    }


    public PageResult(List<T> listData, Integer currentPage, Integer totalCount, Integer pageSize){
        this.listData=listData;
        this.currentPage=currentPage;
        this.totalCount=totalCount;
        this.pageSize=pageSize;
        this.totalPage=this.totalCount%this.pageSize==0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
        this.prevPage=this.currentPage>1?this.currentPage-1:1;
        this.nextPage=this.currentPage<this.totalPage? this.currentPage+1:this.totalPage;
    }

    public Integer getTotalPage(){
        return totalPage==0?1:totalPage;
    }

}

